package com.ruoyi.onlinevideo.service.impl;/**
 * @InterfaceName: MessageServiceImpl
 * @Description:
 * @Author: YourName
 * @Date: 2023-04-14
 */

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.onlinevideo.domain.Message;
import com.ruoyi.onlinevideo.mapper.MessageMapper;
import com.ruoyi.onlinevideo.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @InterfaceName: MessageServiceImpl
 * @Description:
 * @Author: lilirui
 * @Date: 2023-04-14
 */
@Service("MessageService")
public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> implements MessageService {
    @Autowired
    private MessageMapper messageMapper;

    @Override
    public ArrayList<Long> getHisList(Long userId) {
        return  messageMapper.getUidHisList(userId);
    }

    @Override
    public List<Message> getMsgList(Long userId, Long remoteUid) {
        return messageMapper.selectList(new LambdaQueryWrapper<Message>().eq(Message::getSender, userId).eq(Message::getReceiver,remoteUid).or().eq(Message::getSender, remoteUid).eq(Message::getReceiver, userId).orderByAsc(Message::getCreateTime));
    }

    @Override
    public Message getrecentmsg(Long userId, Long uid) {
        return messageMapper.getrecentmsg( userId,  uid);
    }
}
